<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="/view/conf/farmtag.tld" prefix="PF"%>
<style>
<!--
.farm_tree_flag {
	color: #c3c3c3;
	text-decoration: none;
}

.farm_tree_h {
	color: #c3c3c3;
}

.farm_tree_s {
	color: #e2e2e2;
}
.farm_tree_num{
	color: #D9534F; 
	font-weight: bold;
}

-->
</style>
<div class="row column_box">
	<div class="col-sm-12">
		<span class="glyphicon glyphicon-fire  column_title">&nbsp;知识分类</span>
	</div>
</div>
<div class="panel panel-default  side_column">
	<div class="panel-body">
		<div id="loadingDivId">加载分类中...</div>
		<ul class="doctypeUl">
		</ul>
	</div>
</div>
<script type="text/javascript">
var type_collapse_level=3;
</script>
<PF:IfParameterEquals key="config.sys.type.collapse.level" val="1">
<script type="text/javascript">
var type_collapse_level=1;
</script>
</PF:IfParameterEquals>
<PF:IfParameterEquals key="config.sys.type.collapse.level" val="2">
<script type="text/javascript">
var type_collapse_level=2;
</script>
</PF:IfParameterEquals>
<PF:IfParameterEquals key="config.sys.type.collapse.level" val="3">
<script type="text/javascript">
var type_collapse_level=3;
</script>
</PF:IfParameterEquals>
<script type="text/javascript">
	$(function() {
		$.post('webtype/PubLoadRType.html',{typeid:'${typeid}'}, function(flag) {
			var typeobj=$.parseJSON(flag);
			if(typeobj.types.length==0){
				$('#loadingDivId').html("<div class='alert alert-warning'>无分类信息<br/>请在后台添加分类!</div>");
			}
			//第一层 
			$(typeobj.types).each(function(i, obj1) {
				if (obj1.parentid == "NONE") {
					var html = new Array();
					html.push('<li><h5 class="showLableType"><a id='+obj1.id+'>' + obj1.name + '</a>');
					if (obj1.num > 0) {
						html.push('<span class="farm_tree_num">',obj1.num,'</span>');
					}
					if(type_collapse_level<=1){
						html.push('&nbsp;<a class="glyphicon glyphicon-chevron-down farm_tree_flag ',obj1.id,'"></a>');
					}
					html.push('</h5><ul>');
					//第二层
					$(typeobj.types).each(function(i, obj2) {
						if(obj2.parentid==obj1.id) {
							html.push('<li><h5 class="showLableType"><a id='+obj2.id+'>' + obj2.name + '</a>');
							if (obj2.num > 0) {
								html.push('<span class="farm_tree_num">',obj2.num,'</span>');
							}
							if(type_collapse_level<=2){
								html.push('&nbsp;<a class="glyphicon glyphicon-chevron-down farm_tree_flag ',obj2.id,'"></a>');
							}
							html.push('</h5><ul>');
							//第三层
							$(typeobj.types).each(function(i, obj3) {
								if(obj3.parentid==obj2.id) {
									html.push('<li><h5 class="showLableType"><a id='+obj3.id+'>' + obj3.name + '</a>');
									if (obj3.num > 0) {
										html.push('<span class="farm_tree_num">',obj3.num,'</span>');
									}
									if(type_collapse_level<=3){
										html.push('&nbsp;<a class="glyphicon glyphicon-chevron-down farm_tree_flag ',obj3.id,'"></a>');
									}
									html.push('</h5><ul>');
									//第四层
									$(typeobj.types).each(function(i, obj4) {
										if(obj4.parentid==obj3.id) {
											html.push('<li><h5 class="showLableType"><a id='+obj4.id+'>' + obj4.name + '</a>');
											if (obj4.num > 0) {
												html.push('<span class="farm_tree_num">',obj4.num,'</span>');
											}
											html.push('&nbsp;<a class="glyphicon glyphicon-chevron-down farm_tree_flag ',obj4.id,'"></a></h5><ul>');
											//第五层
											$(typeobj.types).each(function(i, obj5) {
												if(obj5.parentid==obj4.id) {
													html.push('<li><h5 class="showLableType"><a id='+obj5.id+'>' + obj5.name + '</a>');
													if (obj5.num > 0) {
														html.push('<span class="farm_tree_num">',obj5.num,'</span>');
													}
													html.push('&nbsp;<a class="glyphicon glyphicon-chevron-down farm_tree_flag ',obj5.id,'"></a></h5></li>');
												}
											});
											html.push('</ul></li>');
										}
									});
									html.push('</ul></li>');
								}
							});
							html.push('</ul></li>');
						}
					});
					html.push('</ul></li>');
					$('#loadingDivId').html("");
					$('.doctypeUl').append(html.join(""));
					//html.push('');
				}
			});
			//alert(typeobj.types.length);
			initTypesStyle();
			$(typeobj.typepath).each(function(i,obj){
				$('.'+obj.id).click();
			});
		});
	});
	function initTypesStyle(){
		$('a', '.showLableType').bind(
				'click',
				function() {
					if ($(this).attr('id')) {
						window.location = basePath + "webtype/view"
								+ $(this).attr('id') + "/Pub1.html";
					}
				});

		$('.farm_tree_flag').each(function(i, o) {
			if ($(this).parent().next().contents().length <= 1) {
				$(this).removeClass("farm_tree_flag");
				$(this).removeClass("glyphicon");
				$(this).removeClass("glyphicon-chevron-down");
			} else {
				$(this).parent().next().hide();
			}
		});
		$('.farm_tree_flag').bind('click', function() {
			var ul = $(this).parent().next();
			if ($(ul).is(':hidden')) {
				$(this).parent().next().show();
				$(this).removeClass("farm_tree_s");
				$(this).addClass("farm_tree_h");
				$(this).removeClass("glyphicon-chevron-down");
				$(this).addClass("glyphicon-chevron-up");
			} else {
				$(this).parent().next().hide();
				$(this).removeClass("farm_tree_h");
				$(this).addClass("farm_tree_s");
				$(this).removeClass("glyphicon-chevron-up");
				$(this).addClass("glyphicon-chevron-down");
			}
		});
	}
</script>

